﻿/*************************************************************************
 * Created by OhZee Creative, LLC
 * 2013
 * This code is licensed under Microsoft Public License (Ms-PL)
 * http://opensource.org/licenses/ms-pl
 * http://ozframework.codeplex.com/
 *************************************************************************/

namespace OhZeeCreative.Sound.Windows8
{
    using System.Collections.Generic;

	public class SoundRequestCollection
	{
		private object lockObject = new object();
		private Queue<SoundRequest> playList;
		private int idCounter;

		public SoundRequestCollection()
		{
			this.playList = new Queue<SoundRequest>();
		}

		public int Add(SoundItem sound)
		{
			lock (lockObject)
			{
				this.idCounter++;
				SoundRequest request = new SoundRequest(sound, this.idCounter);
				this.playList.Enqueue(request);
				return this.idCounter;
			}
		}

		public SoundRequest Fetch()
		{
			lock (lockObject)
			{
				if (this.playList.Count > 0)
				{
					return this.playList.Dequeue();
				}
			}
			return null;
		}

		public int Bypass()
		{
			lock (lockObject)
			{
				this.idCounter++;
				return this.idCounter;
			}
		}
	}
}
